package crawler;

import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by User on 2017/12/18.
 */
public class JDBCHelper {

    public static Map<String, JdbcTemplate> jdbcTemplateMap = new HashMap<>();

    public static JdbcTemplate createJdbcTemplate(String templateName, String url, String username, String password, Integer initialSize, Integer maxActive) {
        BasicDataSource basicDataSource = new BasicDataSource();
        basicDataSource.setDriverClassName("com.mysql.jdbc.Driver");
        basicDataSource.setUrl(url);
        basicDataSource.setUsername(username);
        basicDataSource.setPassword(password);
        basicDataSource.setInitialSize(initialSize);
        basicDataSource.setMaxActive(maxActive);

        JdbcTemplate template = new JdbcTemplate(basicDataSource);
        jdbcTemplateMap.put(templateName, template);

        return template;
    }

    public static JdbcTemplate getJdbcTemplate(String templateName) {
        return jdbcTemplateMap.get(templateName);
    }

    public static void main(String[] args) {

        JdbcTemplate jdbcTemplate = getJdbcTemplate("1");



    }


}
